package com.soufang.soufangdemo.base;

public class ApiResponse<T> {
    private Integer code;
    private String message;
    private T data;

    public static ApiResponse<Object> success() {
        return new ApiResponse<>();
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(data);
    }

    public static ApiResponse<Object> error(Integer code, String message) {
        return new ApiResponse<>(code, message);
    }

    public static <T> ApiResponse<T> error(Integer code, String message, T data) {
        return new ApiResponse<>(code, message, data);
    }

    public static <T> ApiResponse<T> error(Status status) {
        return new ApiResponse<>(status.value(), status.getReasonPhrase());
    }


    public ApiResponse() {
        this.code = 0;
        this.message = "SUCCESS";
    }

    public ApiResponse(T data) {
        this();
        this.data = data;
    }

    public ApiResponse(Integer code, String message) {
        this(code, message, null);
    }

    public ApiResponse(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
